package cn.edu.service.impl;

import cn.edu.mapper.lead_TeacherMapper;
import cn.edu.mapper.lead_thesisMapper;
import cn.edu.pojo.All;
import cn.edu.pojo.PageBean;
import cn.edu.pojo.thesis;
import cn.edu.service.lead_TeacherService;
import cn.edu.service.lead_thesisService;
import cn.edu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @author Davey chan
 */
public  class lead_thesisServiceImpl implements lead_thesisService {
    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();


    @Override
    public PageBean<thesis> selectByPageAndcondition(int currentPage, int pageSize, thesis t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        lead_thesisMapper mapper = sqlSession.getMapper(lead_thesisMapper.class);
//     计算开始的索引
        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;

        String thesisName = t.getThesisName();
        if(thesisName !=null && thesisName.length()>0){
            t.setThesisName("%"+thesisName+"%");
        }
        String Category = t.getCategory();
        if(Category !=null && Category.length()>0){
            t.setCategory("%"+Category+"%");

        }






        List<thesis> rows = mapper.selectBypage(begin, size,t);
//        查询总记录数
        int totalCount = mapper.selectTotalCount(t);
//封装pageBean

        PageBean<thesis> pageBean=new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setTotalCount(totalCount);

        sqlSession.close();
        return pageBean;
    }


}
